package com.penghaisoft.microwms.material.web.insidewarehouse.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.penghaisoft.microwms.common.controller.BaseController;
import com.penghaisoft.microwms.common.dto.Resp;
import com.penghaisoft.microwms.common.dto.TransResult;
import com.penghaisoft.microwms.common.page.Pager;
import com.penghaisoft.microwms.common.wms.model.RawContractChangePlanSn;
import com.penghaisoft.microwms.material.web.insidewarehouse.service.IRawContractChangePlanSnService;

import lombok.extern.slf4j.Slf4j;

/** 
 * @Package com.penghaisoft.microwms.material.web.insidewarehouse.controller
 * @ClassName: RawContractChangePlanSnController
 * @Description: 原材料合同更改明细表
 * @author luoteng
 * @date 2019年3月7日 下午1:10:54
 */
@RestController
@RequestMapping(value = "/rawContractChangeSn")
@Slf4j
public class RawContractChangePlanSnController extends BaseController {
	
		@Autowired
		private IRawContractChangePlanSnService rawContractChangePlanSnService;

	  /**
	   * 新增记录
	   * @param rawContractChangePlanSn
	   * @return
	   */
		@PostMapping("c")
		public TransResult create(RawContractChangePlanSn rawContractChangePlanSn) {
			rawContractChangePlanSn.preInsert();
			Resp resp =  rawContractChangePlanSnService.create(rawContractChangePlanSn);
			return fromResp(resp);
		}

	  /**
	   * 删除记录（逻辑删除active_flag=0)
	   * @param rawContractChangePlanSn
	   * @return
	   */
		@PostMapping("d")
		public TransResult delete(RawContractChangePlanSn rawContractChangePlanSn) {
			rawContractChangePlanSn.preUpdate();
			Resp resp =  rawContractChangePlanSnService.delete(rawContractChangePlanSn);
			return fromResp(resp);
		}

	  /**
	   * 查询列表
	   * @param pager
	   * @return
	   */
		@PostMapping("list")
		public TransResult list(@RequestParam(name = "page", defaultValue = "1") int page,
                            @RequestParam(name = "rows", defaultValue = "10") int rows,RawContractChangePlanSn rawContractChangePlanSn) {
			Pager<RawContractChangePlanSn> result = rawContractChangePlanSnService.findListByCondition(page,rows,rawContractChangePlanSn);
			return success(result);
		}

	  /**
	   * 查询单条
	   * @param id
	   * @return
	   */
		@GetMapping("r/{id}")
		public TransResult queryById(@PathVariable String id) {
			RawContractChangePlanSn  rawContractChangePlanSn = rawContractChangePlanSnService.findById(id);
			return success(rawContractChangePlanSn);
		}

	  /**
	   * 修改记录
	   * @param rawContractChangePlanSn
	   * @return
	   */
		@PostMapping("u")
		public TransResult update(RawContractChangePlanSn rawContractChangePlanSn) {
			rawContractChangePlanSn.preUpdate();
			Resp resp =  rawContractChangePlanSnService.update(rawContractChangePlanSn);
	    	return fromResp(resp);
		}

}
